package com.isoft.service.impl;

import com.isoft.service.DfmeDepeService;
import com.isoft.service.XmlFileHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;

@Component
public class DfmeDepeFileHandler implements XmlFileHandler {        //特定XML文件处理器实现示例
    private static final Logger logger = LoggerFactory.getLogger(DfmeDepeFileHandler.class);

    private final DfmeDepeService dfmeDepeService;

    public DfmeDepeFileHandler(DfmeDepeService dfmeDepeService) {
        this.dfmeDepeService = dfmeDepeService;
    }

    @Override
    public boolean supports(Path filePath) {
        return filePath.getFileName().toString().matches("DFME-DEPE.*\\.xml");
    }

    @Override
    public String handle(Path filePath) throws Exception {
        // 读取文件内容为字符串
        String xmlContent = Files.readString(filePath, StandardCharsets.UTF_8);
        return dfmeDepeService.parseAndSave(xmlContent);
    }
}
